package com.rj.framework.workflow;

import com.rj.framework.component.BusinessComponent;
import com.rj.framework.component.ComponentRegistry;
import com.rj.framework.component.TechnicalComponent;
import com.rj.framework.context.Context;
import com.rj.framework.transformer.TransformationRegistry;

/**
 * 工作流定义
 */
public abstract class WorkflowDefinition<I, O> {
    private final ComponentRegistry componentRegistry;
    private final TransformationRegistry transformationRegistry;

    protected WorkflowDefinition(ComponentRegistry componentRegistry, TransformationRegistry transformationRegistry) {
        this.componentRegistry = componentRegistry;
        this.transformationRegistry = transformationRegistry;
    }

    public abstract O execute(I input, Context<?> context);

    protected <I, T, C extends Context<?>> BusinessComponent<I, T, C> getBusinessComponent(Class<? extends BusinessComponent<I, T, C>> componentClass) {
        return componentRegistry.getBusinessComponent(componentClass);
    }

    protected <I, O, C extends Context<?>> TechnicalComponent<I, O, C> getTechnicalComponent(Class<? extends TechnicalComponent<I, O, C>> componentClass) {
        return componentRegistry.getTechnicalComponent(componentClass);
    }

    protected <T> T transform(Object source, Class<T> targetType) {
        return transformationRegistry.transform(source, targetType);
    }
}